﻿using System;
using System.Collections.Generic;
using Autodesk.Revit.DB;
using YJKArch.Utils;

namespace YJKArch.AreaStatistical.TableTools
{
	public class TableInfos
	{
		public TableHead Head
		{
			get
			{
				return this.m_TableHeadData;
			}
			set
			{
				this.m_TableHeadData = value;
			}
		}

		public TableBody Body
		{
			get
			{
				return this.m_TableBodyData;
			}
			set
			{
				this.m_TableBodyData = value;
			}
		}

		public TableHead._Tag_HeadType TableHeadType
		{
			get
			{
				return this.m_TableHeadData.HeadType;
			}
		}

		public double HMargin
		{
			get
			{
				return this.m_HMargin;
			}
			set
			{
				this.m_HMargin = value;
			}
		}

		public double VMargin
		{
			get
			{
				return this.m_VMargin;
			}
			set
			{
				this.m_VMargin = value;
			}
		}

		public bool AutoCellsSize
		{
			get
			{
				return this.m_AutoCellsSize;
			}
			set
			{
				this.m_AutoCellsSize = value;
			}
		}

		public TextNoteType FontSetting
		{
			get
			{
				return this.m_FontSetting;
			}
		}

		public TableInfos()
		{
		}

		public TableInfos(TableInfos tableInfos)
		{
			this.m_TableHeadData = tableInfos.m_TableHeadData;
			this.m_TableBodyData = tableInfos.m_TableBodyData;
			this.m_FontSetting = tableInfos.m_FontSetting;
			this.m_HMargin = tableInfos.m_HMargin;
			this.m_VMargin = tableInfos.m_VMargin;
			this.m_AutoCellsSize = tableInfos.m_AutoCellsSize;
		}

		public TableInfos(TableHead tableHeadData, TableBody tableBodyData, TextNoteType fontSetting, double hMargin, double vMargin, bool autoCellsSize)
		{
			this.m_TableHeadData = tableHeadData;
			this.m_TableBodyData = tableBodyData;
			this.m_FontSetting = fontSetting;
			this.m_HMargin = hMargin;
			this.m_VMargin = vMargin;
			this.m_AutoCellsSize = autoCellsSize;
		}

		public bool IsNull()
		{
			return this.m_TableHeadData.IsNull();
		}

		public List<string> EffectiveColumnNameList()
		{
			List<string> list = new List<string>();
			foreach (TableHeadCell tableHeadCell in this.m_TableHeadData.GetEffectiveRow())
			{
				list.Add(tableHeadCell.Value);
			}
			return list;
		}

		public List<double> EffectiveColumnWidthList()
		{
			List<double> list = new List<double>();
			List<TableHeadCell> effectiveRow = this.m_TableHeadData.GetEffectiveRow();
			for (int i = 0; i < effectiveRow.Count; i++)
			{
				list.Add(this.m_TableHeadData.GetEffectiveRowItemWidthByIndex(i));
			}
			return list;
		}

		public void SetEffectiveColumnWidthList(List<double> effectiveColumnWidthList)
		{
			for (int i = 0; i < effectiveColumnWidthList.Count; i++)
			{
				this.m_TableHeadData.SetEffectiveRowItemWidthByIndex(i, effectiveColumnWidthList[i]);
			}
		}

		public List<TableHeadCellKey> EffectiveColumnParameterList()
		{
			List<TableHeadCellKey> list = new List<TableHeadCellKey>();
			foreach (TableHeadCell tableHeadCell in this.m_TableHeadData.GetEffectiveRow())
			{
				list.Add(tableHeadCell.Key);
			}
			return list;
		}

		public List<TableBodyCell._tagDataType> ColumnValueTypeList()
		{
			List<TableBodyCell._tagDataType> list = new List<TableBodyCell._tagDataType>();
			if (this.m_TableBodyData.BodyData.Count < 1)
			{
				return list;
			}
			foreach (TableBodyCell tableBodyCell in this.m_TableBodyData.BodyData[0].RowData)
			{
				list.Add(tableBodyCell.DataType);
			}
			return list;
		}

		public void SetFontSetting(TextNoteType fontSetting)
		{
			this.m_FontSetting = fontSetting;
		}

		public string FontName()
		{
			if (this.m_FontSetting == null)
			{
				return "";
			}
			return this.m_FontSetting.Name;
		}

		public double FontHeight()
		{
			if (this.m_FontSetting == null)
			{
				return 2.5;
			}
			Parameter parameter = this.m_FontSetting.get_Parameter(BuiltInParameter.TEXT_SIZE);
			if (parameter == null)
			{
				throw new Exception("parameter 'TEXT_SIZE' is null.");
			}
			return Common.FeetToMM(parameter.AsDouble());
		}

		public double FontWidthScale()
		{
			if (this.m_FontSetting == null)
			{
				return 0.7;
			}
			Parameter parameter = this.m_FontSetting.get_Parameter(BuiltInParameter.TEXT_WIDTH_SCALE);
			if (parameter == null)
			{
				throw new Exception("parameter 'TEXT_WIDTH_SCALE' is null.");
			}
			return Common.FeetToMM(parameter.AsDouble());
		}

		private TableHead m_TableHeadData = new TableHead();

		private TableBody m_TableBodyData = new TableBody();

		private TextNoteType m_FontSetting;

		private double m_HMargin = 1.0;

		private double m_VMargin = 1.5;

		private bool m_AutoCellsSize;
	}
}
